Push and periodic notifications client-side sample


Windows Runtime, Windows 8.1, Windows Phone 8.1
User Interface, universal app
Windows RT
en-US
4/2/2014

This sample shows how a client app can register and listen for push notifications that are sent from a web server. Push notifications can be used to update a badge or a tile, raise a toast notification, or launch a background task. Periodic notifications act in the other direction, polling a web server for tile or badge content at a fixed time interval.

Note  This sample was created using one of the universal app templates available in Visual Studio. It shows how its solution is structured so it can run on both Windows 8.1 and Windows Phone 8.1. For more info about how to build apps that target Windows and Windows Phone with Visual Studio, see Build apps that target Windows and Windows Phone 8.1 by using Visual Studio.

The sample demonstrates the following actions:

  • Requesting a channel URI through which the push notifications will be sent
  • Renewing a channel
  • Listening for push notifications from the web server
  • Polling a web server for updated tile content
  • Polling a web server for updated badge content

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.

Note  For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.

Related topics

For JavaScript/HTML developers
Sending push notifications with WNS
How to authenticate with the Windows Push Notification Service (WNS)
How to request, create, and save a notification channel
How to set up periodic notifications for tiles
How to set up periodic notifications for badges
How to update a badge through push notifications
Quickstart: Sending a tile push notification
Quickstart: Sending a toast push notification
For C#/C++/XAML developers
Sending push notifications with WNS
How to authenticate with the Windows Push Notification Service (WNS)
How to request, create, and save a notification channel
How to set up periodic notifications for tiles
How to set up periodic notifications for badges
How to update a badge through push notifications
Quickstart: Sending a tile push notification
Quickstart: Sending a toast push notification
Related samples
Raw notifications sample
Windows 8 Windows Store app samples download pack

Operating system requirements

Client
Windows 8.1
Server
Windows Server 2012 R2
Phone
Windows Phone 8.1

Run the sample

The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.

Deploying the sample

  • To deploy the built Windows version of the sample:

    1. Select PushAndPeriodicNotifications.Windows in Solution Explorer.
    2. Use Build > Deploy Solution or Build > Deploy PushAndPeriodicNotifications.Windows.
  • To deploy the built Windows Phone version of the sample:

    1. Select PushAndPeriodicNotifications.WindowsPhone in Solution Explorer.
    2. Use Build > Deploy Solution or Build > Deploy PushAndPeriodicNotifications.WindowsPhone.

Deploying and running the sample

  • To deploy and run the Windows version of the sample:

    1. Right-click PushAndPeriodicNotifications.Windows in Solution Explorer and select Set as StartUp Project.
    2. To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
  • To deploy and run the Windows Phone version of the sample:

    1. Right-click PushAndPeriodicNotifications.WindowsPhone in Solution Explorer and select Set as StartUp Project.
    2. To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
    3. Give it several seconds to launch in the emulator (it takes over the full screen, so if you're still seeing your Start screen tiles, the sample hasn't launched yet), after which you can find the sample in the Apps list. Add the tile's sample to the Start screen so that you can see the result of the action that you've taken in the sample. A tile must be pinned to the Start screen to receive notifications.

How to use the sample

For any functionality that involves non-local content, the developer must have declared the "Internet (Client)" capability in the app's manifest. In the Visual Studio 2013 manifest editor, this option is under the Capabilities tab.

To run this sample, you need access to a web server that can store your notification channel, send push notifications to your client, and provide tile and badge update content when polled.

For tile and badge push notifications to work, your app tile must be able to receive notifications. Tile notifications can be disabled by a user for a single app or for all apps, or by a system administrator through group policy.

Windows Phone: External to this sample, you can experiment with push notifications in the Windows Phone emulator, through its Additional Tools flyout. This uses only local resources and does not require a web server, but it appears to the app that it is receiving a notification through Windows Push Notification Services (WNS).